% Copyright 2009 Neurosciences Research Foundation, Incorporated

% function finds local min of cost measure starting at conn_data_in params.
% This is meant to be called by cmaes to combine evolutionary search with
% local minimization search like Zoran paper.
function [cost_measure best_params] = spnet_som_local_min( conn_data, min_conn_data, max_conn_data)

persistent lowest_cost

if isempty(lowest_cost)
    lowest_cost = 1e10;
end

%options = optimset('UseParallel','always');
options = optimset('UseParallel','never');

[best_params, cost_measure] = fmincon( @spnet_som_test, conn_data, [], [] , [],[],min_conn_data, max_conn_data,[], options);
lowest_cost
if cost_measure < lowest_cost
    lowest_cost = cost_measure;
    save 'best_spnet_som_local_min' best_params cost_measure;
end